package routes

import (
	"github.com/flaravel/quanlaolao/app/http/controllers"
	"github.com/flaravel/quanlaolao/app/http/middlewares"
	"github.com/gorilla/mux"
	"net/http"
)

func RegisterWebRoutes(router *mux.Router) {

	router.Use(middlewares.StartSession)
	index := new(controllers.QllController)
	router.HandleFunc("/", index.Index).Methods("GET").Name("qll.index")

	// 静态页面
	pc := new(controllers.PagesController)
	router.NotFoundHandler = http.HandlerFunc(pc.NotFound)
	router.HandleFunc("/about", pc.About).Methods("GET").Name("qll.about")

	// 券姥姥组织
	ch := new(controllers.ChannelController)
	router.HandleFunc("/channel", ch.Index).Methods("GET").Name("channel.index")
	router.HandleFunc("/channel/create", ch.Create).Methods("GET").Name("channel.create")
	router.HandleFunc("/channel/{id:[0-9]+}/edit", ch.Edit).Methods("GET").Name("channel.edit")
	router.HandleFunc("/channel", ch.Store).Methods("POST").Name("channel.store")
	router.HandleFunc("/channel/{id:[0-9]+}", ch.Update).Methods("POST").Name("channel.update")
	router.HandleFunc("/channel/{id:[0-9]+}/delete", ch.Delete).Methods("POST").Name("channel.delete")

	// Cps
	cps := new(controllers.CpsController)
	router.HandleFunc("/cps",cps.Index).Methods("GET").Name("cps.index")
	router.HandleFunc("/cps/create",cps.Create).Methods("GET").Name("cps.create")
	router.HandleFunc("/cps",cps.Store).Methods("POST").Name("cps.store")
	router.HandleFunc("/cps/{id:[0-9]+}/edit",cps.Edit).Methods("GET").Name("cps.edit")
	router.HandleFunc("/cps/{id:[0-9]+}",cps.Update).Methods("POST").Name("cps.update")
	router.HandleFunc("/cps/{id:[0-9]+}/delete",cps.Delete).Methods("POST").Name("cps.delete")

	// 群裂变
	liebian := new(controllers.LiebianController)
	router.HandleFunc("/liebian",liebian.Index).Methods("GET").Name("liebian.index")
	router.HandleFunc("/liebian/create",liebian.Create).Methods("GET").Name("liebian.create")
	router.HandleFunc("/liebian",liebian.Store).Methods("POST").Name("liebian.store")
	router.HandleFunc("/liebian/{id:[0-9]+}/delete",liebian.Delete).Methods("POST").Name("liebian.delete")

	// 静态资源
	router.PathPrefix("/css/").Handler(http.FileServer(http.Dir("./public")))
	router.PathPrefix("/js/").Handler(http.FileServer(http.Dir("./public")))
	router.PathPrefix("/image/").Handler(http.FileServer(http.Dir("./public")))
	router.PathPrefix("/upload/").Handler(http.FileServer(http.Dir("./public")))
}
